<template>
	<view class="dropWrap-page">
		<!-- 下拉框title -->
		<view @click="showShadow" class="dropWrap" :class="showIf?'isactive':''">{{ list[current].text }}
			<view class="sanjiao"></view>

		</view>

		<view class="dropdown">
			<!-- 遮罩层 -->
			<view :class="showIf ? 'dropdown-mask' : 'undropdown-mask'" @tap.stop="hideShadow"></view>
			<!-- <view class="ul" :style="showIf?'height:'+list.length*30+'px':''"> -->
			<view class="ul" :style="'--i:'+list.length" :class="showIf?'show':''">
				<!-- 不支持就用上面那种 -->
				<view class="li" :class="{'blue':current==item.value}" v-for="(item, index) in list" :key="index"
					@tap.stop="handlerItem(item.value)">{{ item.text }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'dropdown',
		props: {
			catename: {
				type: Object,
				default: function() {
					return {}
				}
			},
			list: {
				type: Array,
				default: () => []
			},
			current: {
				type: [String, Number],
				default: 0
			}
		},
		data() {
			return {
				//显示分类列表
				showIf: false
			};
		},
		methods: {
			handlerItem(value) {
				
				var that = this
				// if(that.catename=='sort'){
				that.catename.value = value
				this.$emit('selectCate', that.catename);
				// }
				this.showIf = false
				// this.$emit('selectCate', value);
			},
			// 点击空白关闭菜单框
			hideShadow() {
				this.showIf = false;

			},
			//显示分类列表
			showShadow() {
				this.showIf = true;
				this.$emit('showCate', this.catename);
			}
		}
	};
</script>

<style scoped lang="scss" scoped>
	.dropWrap-page {
		// width: 100%;

		.dropWrap {
			position: relative;
			// z-index: 102;
			box-sizing: border-box;
			// width: 240upx;
			// width: 100%;
			// width: 335upx;
			// height: 52upx;
			height: 90upx;
			border: 1px solid #e8ecef;
			font-size: 24upx;
			color: #8c9fad;
			padding: 8upx 16upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			// background-color: #fff;

			&.isactive {
				color: #1c7ff6;
			}

			.sanjiao {
				width: 0;
				height: 0;
				border-left: 12upx solid transparent;
				border-right: 12upx solid transparent;
				border-top: 12upx solid #C5CFD5;
				border-bottom: 12upx solid transparent;
				transform: translateY(6upx);
			}
		}

		.dropdown {
			position: absolute;
			z-index: 100;
			right: 30upx;

			.ul {
				width: 240upx;
				// width: 335upx;
				position: relative;
				z-index: 101;
				list-style: none;
				background-color: #fff;
				border-radius: 4rpx;
				padding-left: 0;
				box-shadow: 6rpx 6rpx 10rpx rgba(122, 122, 122, 0.2);
				transition: all 0.2s;
				height: 0;
				overflow: hidden;
				border-radius: 15upx;

				.li {
					box-sizing: border-box;
					color: #333;
					margin: 0 20upx;
					width: 200upx;
					height: 88upx;
					border-bottom: 1px solid #e6eaeb;
					text-align: center;
					font-size: 24rpx;
					line-height: 88upx; //与下面的高度保持一致
					padding-left: 16upx;

					&.blue {

						color: #1c7ff6
					}

				}

				.li:last-child {
					border-bottom: none;
				}
			}

			.show {
				height: auto;
				// height: calc( var(--i) * 30px );   //与上面的高度保持一致
			}

			.dropdown-mask {
				top: 0;
				left: 0;
				position: fixed;
				width: 100vw;
				height: 100vh;
				z-index: 100;
				pointer-events: auto;
				// background-color: #F43F3B;
			}

			.undropdown-mask {
				pointer-events: none;
			}
		}

	}
</style>
